package com.yanqu.road.server.cmd.cross.player;


import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.pb.winery.WineryProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.manger.player.UserMgr;
import com.yanqu.road.server.manger.player.GamePlayerMgr;
import com.yanqu.road.server.protocol.Protocol;
import com.yanqu.road.utils.YanQuMessageUtils;

@Cmd(code = Protocol.S_CROSS_TO_WINERY_VISIT, desc = "跨服拜访玩家酒坊")
public class CrossWineryVisitCmd extends AbstractCommand {


    private WineryProto.CrossWineryVisitReqMsg reqMsg;

    private WineryProto.CrossWineryVisitRespMsg.Builder respMsgBuilder;

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        this.reqMsg = WineryProto.CrossWineryVisitReqMsg.parseFrom(packet.getBytes());
        return true;
    }

    @Override
    public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
        this.respMsgBuilder = WineryProto.CrossWineryVisitRespMsg.newBuilder();
        WineryProto.WineryVisitRespMsg.Builder wineryVisit = UserMgr.wineryVisit(this.reqMsg.getVisitId());
        this.respMsgBuilder.setRespData(wineryVisit);
    }

    @Override
    public void sendData(GamePlayer player) {
        this.respMsgBuilder.setUserId(this.reqMsg.getUserId());
        this.respMsgBuilder.setServerId(this.reqMsg.getServerId());
        YanQuMessage pbMsg = YanQuMessageUtils.buildMessage(Protocol.C_CROSS_WINERY_VISIT_RESP, this.respMsgBuilder);
        GamePlayerMgr.sendPacket(0, pbMsg);
    }

    @Override
    public boolean isDebug() {
        return super.isDebug();
    }

    @Override
    public String getRequestData() {
        return super.getRequestData();
    }
}
